#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define MAXLENGTH 1000

bool find(char *quacks, int quacksLength) {
    
    char quack[5] = {'q', 'u', 'a', 'c', 'k'}; // 贪心数组
    int index = 0;
    int quacksIndex[5] = {-1, -1, -1, -1, -1};
    bool isFind = false;

    for(int i = 0; i < quacksLength; i++) {
        if (quacks[i] == quack[index]) {
            quacksIndex[index++] = i;
        }
        if (index == 5) {
            isFind = true;
            index = 0;
            for(int i = 0; i < 5; i++) {
                quacks[quacksIndex[i]] = 0;
                quacksIndex[i] = -1;
            }
        }
    }

    return isFind;
};

int main() {

    char input[MAXLENGTH];
    scanf("%s", input);
    int quacksLength = strlen(input);

    int least = 0;

    while(find(input, quacksLength)) {
        least ++;
    }

    printf("%d\n", least == 0 ? -1 : least);

    return 0;
}